Result type of before(), after(), below()

What is the result type of the DXL functions before(Object o), after(Object o), and below(Object o)?
In the reference manual they are used only directly as arguments of create().

I want to write following function:

??? getInsertPosition(Object o) {
    if (...)
        return below(o);
    else if (...)
        return after(o);
    else
        return before(o);
}

??? insertPos = getInsertPosition(o);
Object newObj = create(insertPos);

UweR - Tue Jun 30 06:49:12 EDT 2015

Re: Result type of before(), after(), below()
pommCannelle - Tue Jun 30 08:13:13 EDT 2015

Hi !

why don't you try something like ... 

Object createNewObj(Object o) {
    if (...)
        return create(below o)
    else if (...)
        return create(after o)
    else
        return create(before o)

}
Object newObj = createNewObj(o)

?? 

Re: Result type of before(), after(), below()
Wolfgang Uhr - Tue Jun 30 08:31:16 EDT 2015

Hi

The result is of type Object. The best explanation you'll find if you search for "Vertical navigation"

Best regards

Wolfgang

Re: Result type of before(), after(), below()
Mathias Mamsch - Tue Jun 30 09:06:37 EDT 2015

What you are trying to do won't work, because before (...), after(...), etc. return different types (which - by the way - you can get from the perms list , that you can download on this forum). Instead you should use a DxlObject or custom struct. Code like this quickly gets complex (when you try to handle the special cases, like create as first object in module, create table cell, etc.). Therefore especially for library code I would recommend a class based approach.

// ************************** enum Position **************************
struct Position {}

Position BEFORE = addr_ 1
Position AFTER  = addr_ 2

// stringOf 
string gPositionString[] = { "NULL", "before", "after" }
string stringOf (Position p) { return gPositionString[((addr_ p) int)]; }


// *************************** class Position ************************* 

struct InsertPosition {}

InsertPosition createInsertPosition_ () { DxlObject x = new(); return ((addr_ x) InsertPosition); }
DxlObject DxlObjectOf (InsertPosition this) { return ((addr_ this) DxlObject); }

// property Position
Position getPosition (InsertPosition this) { return ((DxlObjectOf this)->"Position") Position; }
void setPosition(InsertPosition this, Position p) { (DxlObjectOf this)->"Position" = p; }

// property Object
Object getObject(InsertPosition this) {  return ((DxlObjectOf this)->"Object") Object; }
void setObject(InsertPosition this, Object p) { (DxlObjectOf this)->"Object" = p; }


// Methods

Object createObject (InsertPosition this) {
    Position pos = getPosition this; 
    if (pos == AFTER) { return create after (getObject this); }
    if (pos == BEFORE) { return create before (getObject this); }
    error "Invalid position ..."; 
}



// constructors 
InsertPosition createBefore (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, BEFORE); setObject(p, o); return p; }
InsertPosition createAfter  (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, AFTER); setObject(p, o); return p; }

InsertPosition p1 = createBefore (current); 

print "Position p1 is " (stringOf getPosition p1) "\n"

Hope this helps, regards, Mathias

 

Re: Result type of before(), after(), below()
Wolfgang Uhr - Tue Jun 30 12:13:03 EDT 2015

Mathias Mamsch - Tue Jun 30 09:06:37 EDT 2015

What you are trying to do won't work, because before (...), after(...), etc. return different types (which - by the way - you can get from the perms list , that you can download on this forum). Instead you should use a DxlObject or custom struct. Code like this quickly gets complex (when you try to handle the special cases, like create as first object in module, create table cell, etc.). Therefore especially for library code I would recommend a class based approach.

// ************************** enum Position **************************
struct Position {}

Position BEFORE = addr_ 1
Position AFTER  = addr_ 2

// stringOf 
string gPositionString[] = { "NULL", "before", "after" }
string stringOf (Position p) { return gPositionString[((addr_ p) int)]; }


// *************************** class Position ************************* 

struct InsertPosition {}

InsertPosition createInsertPosition_ () { DxlObject x = new(); return ((addr_ x) InsertPosition); }
DxlObject DxlObjectOf (InsertPosition this) { return ((addr_ this) DxlObject); }

// property Position
Position getPosition (InsertPosition this) { return ((DxlObjectOf this)->"Position") Position; }
void setPosition(InsertPosition this, Position p) { (DxlObjectOf this)->"Position" = p; }

// property Object
Object getObject(InsertPosition this) {  return ((DxlObjectOf this)->"Object") Object; }
void setObject(InsertPosition this, Object p) { (DxlObjectOf this)->"Object" = p; }


// Methods

Object createObject (InsertPosition this) {
    Position pos = getPosition this; 
    if (pos == AFTER) { return create after (getObject this); }
    if (pos == BEFORE) { return create before (getObject this); }
    error "Invalid position ..."; 
}



// constructors 
InsertPosition createBefore (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, BEFORE); setObject(p, o); return p; }
InsertPosition createAfter  (Object o) { InsertPosition p = createInsertPosition_(); setPosition (p, AFTER); setObject(p, o); return p; }

InsertPosition p1 = createBefore (current); 

print "Position p1 is " (stringOf getPosition p1) "\n"

Hope this helps, regards, Mathias

 

Mathias you know, that doxygen has some problems by parsing lines like this?

Position BEFORE = addr_ 1

Why don't you use

Position BEFORE = addr_(1);

?

Re: Result type of before(), after(), below()
Mathias Mamsch - Tue Jun 30 15:28:15 EDT 2015

Wolfgang Uhr - Tue Jun 30 12:13:03 EDT 2015

Mathias you know, that doxygen has some problems by parsing lines like this?

Position BEFORE = addr_ 1

Why don't you use

Position BEFORE = addr_(1);

?

Sorry, I wrote that kind of "on-the-fly" and so I did not spend any time on getting that library ready. There is only an example for how you can go about these kind of problems by creating your own structs.

Re: Result type of before(), after(), below()
llandale - Mon Jul 06 16:22:35 EDT 2015

Less elegant but easier to grasp:

  • string c_Pos_Before = 0,
    c_Pos_After = 1,
    c_Pos_Below = 2
  • int getInsertPosition(Object o) {
        if (...)
            return c_Pos_Before;
        else if (...)
            return c_Pos_After;
        else
            return c_Pos_Below;
    }

    int insertPos = getInsertPosition(o);

  • Object oNew
    if (insertPos == c_Pos_Before) then oNew = create(before(o))
    elseif(insertPos == c_Pos_After) then oNew = create(after(o))
    elseif(insertPos == c_Pos_Below) then oNew = create(below(o))

That was scribbling, no attempt to interpret.

-Louie

You know, I've never notice "before" before.  I'm guessing it respects the current display set.  I notice "move(o)" has no such "before" option.  Curious.